<!--
 * @Author: byron
 * @Date: 2021-09-01 20:54:01
 * @LastEditTime: 2021-09-01 21:27:19
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 准备容器 -->
    <div id="test"></div>

    <!-- 引入必要的js库 -->
    <script type="text/javascript" src="../lib/react.development.js"></script>
    <script type="text/javascript" src="../lib/react-dom.development.js"></script>
    <!-- 引入babel库进行语法转化 -->
    <script type="text/javascript" src="../lib/babel.min.js"></script>


    <script type="text/babel">
        class Login extends React.Component{
            state = {
                opacity:1,
            }
            unshow = () => {
                ReactDOM.unmountComponentAtNode(document.querySelector('#test'))
            }
            
            // 生命周期函数
            componentDidMount(){
                // 设置定时器
                this.timer = setInterval(()=>{
                    let {opacity} = this.state

                    opacity -= 0.1

                    if(opacity<=0){
                        opacity=1
                    }
                    
                    this.setState({
                        opacity
                    })
                },200)
            }

            // 组件销毁
            componentWillUnmount(){
                // 清除定时器
                clearInterval(this.timer)
            }

            render(){
                return (
                    <div>
                        <div style={{opacity:this.state.opacity}}>好好学习</div>
                        <button onClick={this.unshow}>消失</button>
                    </div>
                )
            }
        }
        ReactDOM.render(<Login />,document.querySelector('#test'))
    </script>
</body>

</html>